//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me;

import java.awt.*;
import javax.swing.*;

// Referenced classes of package org.jpgolay.me:
//            AppMenuGUI, AppToolBarGUI
public class AppMainGUI extends JFrame {

    public AppMainGUI()
            throws HeadlessException {
        jContentPane = null;
        appMenuGUI = null;
        jScrollPane = null;
        jDesktopPane = null;
        appToolBar = null;
        backgroundJLabel = null;
        backgroundIcon = null;
        initialize();
    }

    public AppMainGUI(GraphicsConfiguration gc) {
        super(gc);
        jContentPane = null;
        appMenuGUI = null;
        jScrollPane = null;
        jDesktopPane = null;
        appToolBar = null;
        backgroundJLabel = null;
        backgroundIcon = null;
        initialize();
    }

    public AppMainGUI(String title)
            throws HeadlessException {
        super(title);
        jContentPane = null;
        appMenuGUI = null;
        jScrollPane = null;
        jDesktopPane = null;
        appToolBar = null;
        backgroundJLabel = null;
        backgroundIcon = null;
        initialize();
    }

    public AppMainGUI(String title, GraphicsConfiguration gc) {
        super(title, gc);
        jContentPane = null;
        appMenuGUI = null;
        jScrollPane = null;
        jDesktopPane = null;
        appToolBar = null;
        backgroundJLabel = null;
        backgroundIcon = null;
        initialize();
    }

    private void initialize() {
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/org/jpgolay/me/images/logo.gif")));
        setTitle("JGESTCOM 4.01");
        setJMenuBar(getAppMenuGUI());
        setSize(854, 554);
        setContentPane(getJContentPane());
    }

    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getJScrollPane(), "Center");
            jContentPane.add(getAppToolBar(), "West");
        }
        return jContentPane;
    }

    private AppMenuGUI getAppMenuGUI() {
        if (appMenuGUI == null) {
            appMenuGUI = new AppMenuGUI();
            appMenuGUI.enabledAll(false);
        }
        return appMenuGUI;
    }

    private JScrollPane getJScrollPane() {
        if (jScrollPane == null) {
            jScrollPane = new JScrollPane();
            jScrollPane.setViewportView(getJDesktopPane());
        }
        return jScrollPane;
    }

    private JDesktopPane getJDesktopPane() {
        if (jDesktopPane == null) {
            jDesktopPane = new JDesktopPane();
            jDesktopPane.add(getBackgroundJLabel());
        }
        return jDesktopPane;
    }

    private AppToolBarGUI getAppToolBar() {
        if (appToolBar == null) {
            appToolBar = new AppToolBarGUI();
            appToolBar.setOrientation(1);
            appToolBar.setEnabledAll(false);
        }
        return appToolBar;
    }

    private JLabel getBackgroundJLabel() {
        if (backgroundJLabel == null) {
            backgroundJLabel = new JLabel();
            backgroundJLabel.setIcon(getBackgroundIcon());
            backgroundJLabel.setBounds(getDimension().width / 2 - getBackgroundIcon().getIconWidth() / 2, getDimension().height / 2 - getBackgroundIcon().getIconHeight() / 2, getBackgroundIcon().getIconWidth(), getBackgroundIcon().getIconHeight());
        }
        return backgroundJLabel;
    }

    private Icon getBackgroundIcon() {
        if (backgroundIcon == null) {
            backgroundIcon = new ImageIcon(getClass().getResource("images/splash.png"));
        }
        return backgroundIcon;
    }

    private Dimension getDimension() {
        return Toolkit.getDefaultToolkit().getScreenSize();
    }

    public JDesktopPane getDesktop() {
        return getJDesktopPane();
    }

    public AppToolBarGUI getToolBar() {
        return getAppToolBar();
    }

    public AppMenuGUI getMenu() {
        return getAppMenuGUI();
    }
    private JPanel jContentPane;
    private AppMenuGUI appMenuGUI;
    private JScrollPane jScrollPane;
    private JDesktopPane jDesktopPane;
    private AppToolBarGUI appToolBar;
    private JLabel backgroundJLabel;
    private Icon backgroundIcon;
}
